package com.xc.controller;

import com.xc.model.entity.CompanyEntity;
import com.xc.model.entity.UserEntity;
import com.xc.model.vo.UserVO;
import com.xc.service.UserService;
import com.xc.utils.JSONCopy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//restful风格，post新增，put修改，delete删除get查询
@RestController//返回给前端以对象的形式 json
@RequestMapping("/xc/user")
@Api(tags = "用户管理")
public class UserController {
    //    public Object save
//    前端发送数据给后端以后也是以对象的形式
//    VO  view Object 前端传递到后端的数据
    @Autowired
    private UserService userService;
    @PostMapping
    @ApiOperation(value = "新增", notes = "新增一条数据")
    public Object insert(UserVO userVO) {
        System.out.println("增加");
        return userVO;
    }

    @DeleteMapping
    @ApiOperation("删除")
//    remove
    public Object delete(UserVO userVO) {
        System.out.println("删除");
        return userVO;
    }

    @PutMapping
    public Object update(UserVO userVO) {
        System.out.println("更新");
        return userVO;
    }

    @GetMapping
    public Object getList(UserVO userVO) {
        System.out.println("查询");
        return userService.getList(JSONCopy.copy(userVO, UserEntity.class));
    }

    @GetMapping("/{id}")
    public Object getUserById(@PathVariable("id") Integer id) {
        System.out.println("查询");
        return null;
    }
    @GetMapping("/{username}/{password}")
    public Object aaa(@PathVariable("username") String a,@PathVariable("password") String password) {
        System.out.println("查询");
        return null;
    }

    public static void main(String[] args) {
        CompanyEntity companyEntity = new CompanyEntity();
        companyEntity.setLogo("");
        companyEntity.setPhone("");
        companyEntity.getLogo();
        int[] aa = {1, 2, 3};
        String a = "";
        for (int i = 0; i < 6; i++) {
            a += "a" + i;
        }
        System.out.println(a);
    }
}
